import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/common/xindong_all.dart';
import 'package:xindong/routes/tab_moments/publish/xindong_dongtai_publish_controller.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/common/xindong_app_bar_icon_button.dart';
import 'package:xindong/widgets/common/xindong_button.dart';
import 'package:xindong/widgets/dialog/xindong_cities_sheet.dart';
import 'package:xindong/widgets/image/xindong_media_add_container.dart';

class XinDongDongTaiPublishYeMian extends StatefulWidget {
  const XinDongDongTaiPublishYeMian({super.key});

  @override
  State<XinDongDongTaiPublishYeMian> createState() => _XinDongDongTaiPublishYeMianState();
}

class _XinDongDongTaiPublishYeMianState extends State<XinDongDongTaiPublishYeMian> {
  final _controller = Get.put(XinDongDongTaiPublishController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: XinDongAppBar(
        "",
        leading: const XinDongAppBarIconButton(icon: Icons.close),
        actions: [
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              XinDongCommonButton(
                "发布",
                height: 30,
                textStyle: const TextStyle(fontSize: 14, height: 1.2),
                onTap: () => _controller.authorityEnablePublish(),
              ),
            ],
          ),
          const SizedBox(width: kPaddingValue),
        ],
      ),
      body: GestureDetector(
        onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
        child: GetBuilder<XinDongDongTaiPublishController>(builder: (controller) {
          return ListView(
            children: [
              ConstrainedBox(
                constraints: const BoxConstraints(minHeight: 120, maxHeight: 150),
                child: TextField(
                  keyboardType: TextInputType.multiline,
                  maxLines: null,
                  // 不限制行数
                  style: const TextStyle(color: DZColors.titleColor, fontSize: 16.0, fontWeight: FontWeight.normal),
                  controller: _controller.textEditingController,
                  decoration: const InputDecoration(
                    hintText: "记录这一刻",
                    hintMaxLines: 2,
                    hintStyle: TextStyle(fontSize: 16, color: DZColors.placeholderColor),
                    contentPadding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 16),
                    // 内容偏移上下15，左右16
                    border: OutlineInputBorder(borderSide: BorderSide.none),
                  ),
                ),
              ),
              Container(
                padding: const EdgeInsets.fromLTRB(16, 0.0, 16, 16),
                child: XinDongMediaAddContainer(
                  maxCount: 6,
                  columns: 3,
                  onSelect: (images, video) {
                    _controller.imageFileClassList = images;
                    _controller.videoFileClass = video;
                  },
                ),
              ),
              GestureDetector(
                onTap: () {
                  XinDongCitiesSheet.show(
                    selectText: _controller.publishClass.citys,
                    onDone: (text) {
                      _controller.publishClass.citys = text;
                      _controller.update();
                    },
                  );
                },
                behavior: HitTestBehavior.opaque,
                child: Container(
                  height: 54,
                  color: DZColors.cellColor,
                  padding: const EdgeInsets.only(left: 16, right: 16),
                  child: Row(
                    children: [
                      const Text(
                        "所在城市",
                        style: TextStyle(color: DZColors.titleColor, fontSize: 16),
                      ),
                      const SizedBox(width: 10),
                      Expanded(
                        child: Text(
                          _controller.publishClass.citys,
                          maxLines: 1,
                          textAlign: TextAlign.right,
                          style: const TextStyle(color: DZColors.placeholderColor),
                        ),
                      ),
                      XinDongAll.instance.defaultIconNext,
                    ],
                  ),
                ),
              ),
              Container(
                padding: const EdgeInsets.all(16),
                child: const Text(
                  '请勿上传违规、违法、涉政、涉及种族宗教、敏感低俗的文字、图片和视频，禁止打广告，严重者将做封号处理。',
                  textAlign: TextAlign.center,
                  style: TextStyle(fontSize: 12, fontWeight: FontWeight.normal, color: DZColors.contentColor),
                ),
              ),
            ],
          );
        }),
      ),
    );
  }
}
